package com.itheima.cookie.cookietest3;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

//通过第一次访问cookie判断是否为第一次访问
@WebServlet("/lastTimeCookie1")
public class CookieDemo04 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取名为对象
        Cookie cookie = new Cookie("lastTimeCookie","");

        //设置时间
        cookie.setMaxAge(-1);

        //设置路径
        cookie.setPath("/cookie");

        //上传浏览器
        resp.addCookie(cookie);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
